package com.tianqingwl.gsystem.front.service.impl;

import com.tianqingwl.gsystem.common.enumeration.SysConfigConstants;
import com.tianqingwl.gsystem.content.pojo.ContentInfo;
import com.tianqingwl.gsystem.content.pojo.ContentType;
import com.tianqingwl.gsystem.content.service.ContentInfoService;
import com.tianqingwl.gsystem.content.service.ContentTypeService;
import com.tianqingwl.gsystem.front.service.FrontService;
import com.tianqingwl.gsystem.resources.service.SysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class FrontServiceImpl implements FrontService {
    @Autowired
    private ContentInfoService contentInfoService;
    @Autowired
    private SysConfigService sysConfigService;
    @Autowired
    private ContentTypeService contentTypeService;

    @Override
    public void commonInfo(Model model) {
        //TODO 导航条单做
        List<ContentType> contentTypeList = contentTypeService.listAllType();
        Map<Long,ContentType> contentTypeMap = new HashMap<>();
        for (ContentType contentType : contentTypeList) {
            contentTypeMap.put(contentType.getTypeId(),contentType);
        }
        for (Map.Entry<Long, ContentType> entry : contentTypeMap.entrySet()) {
            ContentType value = entry.getValue();
            if (value.getParentId()!=null){
                contentTypeMap.get(value.getParentId()).getChildList().add(value);
                contentTypeList.remove(value);
            }
        }
        model.addAttribute("contentTypeList",contentTypeList);
        //SEO、底部信息、header(统计js等)
//        Map site_config = sysConfigService.getMapByGroup(SysConfigConstants.Group.site_config);
//        model.addAttribute("site_config",site_config);
        //侧边条
//        List<ContentInfo> hotContent = contentInfoService.listHotContent();
//        model.addAttribute("hotContent",hotContent);
        //热门标签：30条
//        List<Map> maps = contentTypeService.listHotContentTag();
//        model.addAttribute("hotTag",maps);
    }
}
